package com.example.wishstar.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.example.wishstar.MyApplication;
import com.example.wishstar.db.UserDao;
import com.example.wishstar.db.UserDatabase;
import com.example.wishstar.model.Memory;
import com.example.wishstar.repository.MemoryRepository;

import java.util.List;

public class MemoryViewModel extends AndroidViewModel {
    private String TAG = "MemoryViewModel";
    private MemoryRepository memoryRepository;
    private int userId;
    private LiveData<List<Memory>> memoryList;

    public MemoryViewModel(@NonNull Application application) {
        super(application);

        UserDatabase usersDatabse = MyApplication.getUserDatabase();
        UserDao userDao = usersDatabse.userDao();
        memoryRepository = new MemoryRepository(userDao, MyApplication.getApi());
        userId = MyApplication.userId;
        memoryList = memoryRepository.getMemorys(userId);
    }

    public void refresh() {
        memoryRepository.refresh(userId);
    }

    public LiveData<List<Memory>> getMemory() {
        return memoryList;
    }

    public void deleteMemory(int memoryId) {
        memoryRepository.deleteMemoryByMemoryId(memoryId);
    }

}

